package vip.xiaonuo.integrationconfig.model;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@Data
public class DefaultConfiguration implements Serializable {

    private Config config;

    public String gainConfigName(){
        return config.getConfigName();
    }

    public String gainConfigDesc(){
        return StringUtils.isEmpty( config.getDesc()) ? "--" : config.getDesc();
    }

    public List<Attribute> listAttribute(){
        return config.getAttr();
    }

    public String gainProperty(String name){
        List<Attribute> attributes = config.getAttr();
        for(Attribute attr : attributes){
            if(attr.getName().equals(name)){
                return attr.getValue();
            }
        }
        throw new RuntimeException("配置项：" + name + ",不存在");
    }

    public Integer gainIntegerProperty(String name){
        String value = this.gainProperty(name);
        return Integer.parseInt(value);
    }

    public Double gainDoubleProperty(String name){
        String value = this.gainProperty(name);
        return Double.parseDouble(value);
    }

    public Long gainLongProperty(String name){
        String value = this.gainProperty(name);
        return Long.parseLong(value);
    }

    public BigDecimal gainDecimalProperty(String name){
        String value = this.gainProperty(name);
        return new BigDecimal(value);
    }

    public Float gainFloatProperty(String name){
        String value = this.gainProperty(name);
        return Float.parseFloat(value);
    }


}
